﻿using Infragistics.Olap;
using Infragistics.Olap.Data;
using Infragistics.Olap.Data.Base;

namespace PivotGridUsingFlatPivotTable.DataSource
{
    public class FlatPivotDataConnectionSettings : IConnectionSettings
    {
        static FlatPivotDataConnectionSettings()
        {
            // all this is about DataSourceBase to be able to create the proper data provider for your settings
            OlapComposition dataProviderComposition = new OlapComposition();
            dataProviderComposition.AddOlapPart<FlatPivotDataProvider>(typeof(IConnectionSettings));
            dataProviderComposition.AddOlapPart<FlatPivotDataConnectionSettings>();

            OlapContainer<IDataProvider>.Instance.Register(typeof(FlatPivotDataConnectionSettings), dataProviderComposition);

            OlapComposition filterComposition = new OlapComposition();
            filterComposition.AddOlapPart<FilterViewModelBase>(typeof(IOlapViewModel), typeof(IDataProvider), typeof(ICube), typeof(IHierarchy));
            filterComposition.AddOlapPart<FlatPivotDataProvider>(typeof(IConnectionSettings));
            filterComposition.AddOlapPart<FlatPivotDataConnectionSettings>();
            filterComposition.AddOlapPart<Cube>();
            filterComposition.AddOlapPart<Hierarchy>();

            OlapContainer<IFilterViewModel>.Instance.Register(typeof(FlatPivotDataConnectionSettings), filterComposition);

            OlapComposition measureComposition = new OlapComposition();
            measureComposition.AddOlapPart<BaseMeasureViewModel>(typeof(IOlapViewModel), typeof(IDataProvider), typeof(ICube), typeof(IMeasure));
            measureComposition.AddOlapPart<FlatPivotDataProvider>(typeof(IConnectionSettings));
            measureComposition.AddOlapPart<FlatPivotDataConnectionSettings>();
            measureComposition.AddOlapPart<Cube>();
            measureComposition.AddOlapPart<Measure>();

            OlapContainer<IMeasureViewModel>.Instance.Register(typeof(FlatPivotDataConnectionSettings), measureComposition);
        }

        public FlatPivotDataConnectionSettings(IFlatPivotServerDataSource serverDataSource)
        {
            this.ServerDataSource = serverDataSource;
        }

        public IFlatPivotServerDataSource ServerDataSource { get; private set; }
    }
}
